package br.ufrj.dcc.tp.ns.types;

import java.math.BigDecimal;

public class NsTracingPacket extends NsTracingElement {
	
	private PacketEventType event;
	private BigDecimal time;
	// Vamos simplificar o modelo, caso precisamos de todas as informações
	// poderemos recuperar
	private int source, destination, id;
	private PacketType type;
	private NsTracingPacket next;
	
	public PacketEventType getEvent() {
		return event;
	}
	public NsTracingPacket setEvent(PacketEventType event) {
		this.event = event;
		return this;
	}
	public BigDecimal getTime() {
		return time;
	}
	public NsTracingPacket setTime(BigDecimal time) {
		this.time = time;
		return this;
	}
	public int getSource() {
		return source;
	}
	public NsTracingPacket setSource(int source) {
		this.source = source;
		return this;
	}
	public int getDestination() {
		return destination;
	}
	public NsTracingPacket setDestination(int destination) {
		this.destination = destination;
		return this;
	}
	public PacketType getType() {
		return type;
	}
	public NsTracingPacket setType(PacketType type) {
		this.type = type;
		return this;
	}
	public int getId() {
		return id;
	}
	public NsTracingPacket setId(int id) {
		this.id = id;
		return this;
	}
	public NsTracingPacket getNext() {
		return next;
	}
	public NsTracingPacket addNsPacket(NsTracingPacket packet) {
		NsTracingPacket temp = this;
		
		if(this.next == null) {
			this.next = packet;
			return this;
		}
		
		while( (temp = temp.next).next != null);
		
		temp.next = packet;
		
		return this;
	}
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		
		sb	.append(event.getValor())
			.append(" -t ")
			.append(time)
			.append(" -s ")
			.append(source)
			.append(" -d ")
			.append(destination)
			.append(" -p ")
			.append(type.getValor())
			.append(" -i ")
			.append(id);
		
		return sb.toString();
	}
	
	@Override
	public boolean equals(Object o) {
		if(o instanceof NsTracingPacket) {
			return id == ((NsTracingPacket) o).getId();
		}
		return false;
	}
	@Override
	public Class<?> getElementType() {
		return this.getClass();
	}
}